package com.flight.trans.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flight.trans.R;
import com.flight.trans.base.BaseRecyclerAdapter;
import com.flight.trans.base.BaseViewHolder;
import com.flight.trans.bean.LeavePortGroupBoardDetailBean.GroupBoardDetailData.DetailsOrderData;
import com.flight.trans.global.Constant;
import com.flight.trans.util.CommonUtils;

import java.util.List;

/**
 * 出港组板
 */
public class LeavePortGroupBoardDetailsOperationAdapter extends BaseRecyclerAdapter<DetailsOrderData> {


    public LeavePortGroupBoardDetailsOperationAdapter(Context mContext, List<DetailsOrderData> mList , boolean IsEditor) {
        super(mContext, mList);
        this.IsEditor = IsEditor ;
    }

    @Override
    public int setContentView() {
        return R.layout.adapter_leave_port_group_board_details_operation;
    }

    @Override
    protected void bindData(BaseViewHolder holder, DetailsOrderData data, int position) {
        LinearLayout mLlContainerItem = holder.findViewById(R.id.mLlContainerItem);
        TextView mTvPosition = holder.findViewById(R.id.mTvPosition);//序号
        TextView mTvOrderNo = holder.findViewById(R.id.mTvOrderNo);//运单号
        TextView mTvContainerNo = holder.findViewById(R.id.mTvContainerNo);//容器号
        TextView mTvCount = holder.findViewById(R.id.mTvCount);//件数
        TextView mTvWeight = holder.findViewById(R.id.mTvWeight);//重量
        TextView mTvVolume = holder.findViewById(R.id.mTvVolume);//体积
        TextView mTvDeep = holder.findViewById(R.id.mTvDeep);//体积

        CommonUtils.setScreenViewVisible(mTvCount);
        CommonUtils.setScreenViewVisible(mTvWeight);

        mTvPosition.setText((position + 1) + "");

        mTvOrderNo.setText(data.getOrderNo());
        mTvContainerNo.setText(data.getTransportCode());
        mTvCount.setText(String.valueOf(data.getNumber()));
        mTvWeight.setText(String.valueOf(data.getWeight()));
        mTvVolume.setText(CommonUtils.getDoubleFour(data.getVolume()));
        mTvDeep.setText(String.valueOf(data.getDeap()));

        setTextColor(mTvPosition , data.isSelect() || data.isSelected());
        setTextColor(mTvOrderNo , data.isSelect() || data.isSelected());
        setTextColor(mTvContainerNo , data.isSelect() || data.isSelected());
        setTextColor(mTvCount , data.isSelect() || data.isSelected());
        setTextColor(mTvWeight , data.isSelect() || data.isSelected());
        setTextColor(mTvVolume , data.isSelect() || data.isSelected());
        setTextColor(mTvDeep , data.isSelect() || data.isSelected());

        mLlContainerItem.setBackgroundColor(mContext.getResources().getColor(data.isSelected() ? R.color.color_red : (data.isSelect() ? R.color.color_blue : R.color.color_cyan)));

        mTvOrderNo.setBackground(data.getPriorMark() == Constant.Prior_Mark ? mContext.getDrawable(R.mipmap.icon_prepare) : null);

        if(IsEditor) {
            setOnItemClickListener(mLlContainerItem, position);
            setOnItemLongClickListener(mLlContainerItem, position);
            setOnTextClickListener(mTvContainerNo , position);
        }
    }

    private void setTextColor(TextView textView , boolean isSelected){
        textView.setTextColor(mContext.getResources().getColor(isSelected ? R.color.white : R.color.text_color));
    }
}
